home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / FLAME.ZIP / FLAME.PAS
Encoding:
Pascal/Delphi Source File  |  1996-07-10  |  7.9 KB  |  205 lines

  1. {
  2.     Fire v1.0
  3.     Written By Eric Schipper
  4.  
  5. The Flame Effect :-
  6.  
  7.   X = Pixel  A,B,C = Values to average  DV = Decay Value
  8.  
  9.   123  123
  10.   4X5  4X5
  11.   678  ABC  X's colour = A+B+C / 3 ( beacause were adding 3 values ) - DV
  12.         ^────────────────────────────────┐
  13.   ^ X and its surrounding pixel colours. └> X and the pixels we've chosen
  14.  
  15. The basics of the flame effect are to choose as many of the 8 pixels
  16. ( you could use others ) arround the pixel, you are trying to finds
  17. colour, as you want.  Then find the average ( add up all the values and
  18. divide by the ammount of values you added ) of the pixels and then
  19. use this as the pixel's colour.  You have to do this for every one of the
  20. pixels in your pixel array.
  21. Because were calculating values then putting them in the array you can't
  22. just use the screen.  So you are going to have to use another array to do
  23. all your calculations and then move that to the screen.
  24.  
  25. This file is provided so that you programmers who want to write demos and
  26. stuff like that can learn how to.  I've commented most of the source and
  27. have only used a couple of assembler statments so those of you ( you know
  28. who you are ) who don't know how to write in assembler can still know what
  29. is going on, although I can't guarentee that.
  30.  
  31. I would like it if you could send me a message saying what you think of this
  32. and if you have added things I'd also like a copy of the source. You can
  33. mail me at :-
  34.  
  35. The Nooky BBS
  36.  
  37. }
  38.  
  39. Program Flames;
  40.  
  41. Const
  42.   Pal : array[1..768-16*3] Of Byte =
  43.   (   0,  0,  0,  0,  0, 24,  0,  0, 24,  0,  0, 28,
  44.   0,  0, 32,  0,  0, 32,  0,  0, 36,  0,  0, 40,
  45.   8,  0, 40, 16,  0, 36, 24,  0, 36, 32,  0, 32,
  46.   40, 0, 28, 48,  0, 28, 56,  0, 24, 64,  0, 20,
  47.   72, 0, 20, 80,  0, 16, 88,  0, 16, 96,  0, 12,
  48.   104,0, 8, 112,  0,  8,120,  0,  4,128,  0,  0,
  49.   128,0, 0, 132,  0,  0,136,  0,  0,140,  0,  0,
  50.   144,  0,  0,144, 0,  0,148,  0,  0,152,  0,  0,
  51.   156,  0,  0,160, 0,  0,160,  0,  0,164,  0,  0,
  52.   168,  0,  0,172,  0,  0,176,  0,  0,180,  0,  0,
  53.   184,  4,  0,188,  4,  0,192,  8,  0,196,  8,  0,
  54.   200, 12,  0,204, 12,  0,208, 16,  0,212, 16,  0,
  55.   216, 20,  0,220, 20,  0,224, 24,  0,228, 24,  0,
  56.   232, 28,  0,236, 28,  0,240, 32,  0,244, 32,  0,
  57.   252, 36,  0,252, 36,  0,252, 40,  0,252, 40,  0,
  58.   252, 44,  0,252, 44,  0,252, 48,  0,252, 48,  0,
  59.   252, 52,  0,252, 52,  0,252, 56,  0,252, 56,  0,
  60.   252, 60,  0,252, 60,  0,252, 64,  0,252, 64,  0,
  61.   252, 68,  0,252, 68,  0,252, 72,  0,252, 72,  0,
  62.   252, 76,  0,252, 76,  0,252, 80,  0,252, 80,  0,
  63.   252, 84,  0,252, 84,  0,252, 88,  0,252, 88,  0,
  64.   252, 92,  0,252, 96,  0,252, 96,  0,252,100,  0,
  65.   252,100,  0,252,104,  0,252,104,  0,252,108,  0,
  66.   252,108,  0,252,112,  0,252,112,  0,252,116,  0,
  67.   252,116,  0,252,120,  0,252,120,  0,252,124,  0,
  68.   252,124,  0,252,128,  0,252,128,  0,252,132,  0,
  69.   252,132,  0,252,136,  0,252, 136,   0,252, 140,   0,
  70.   252,152,  0,252, 152,   0,252, 156,   0,252, 156,   0,
  71.   252,160,  0,252, 160,   0,252, 164,   0,252, 164,   0,
  72.   252,168,  0,252, 168,   0,252, 172,   0,252, 172,   0,
  73.   252,176,  0,252, 176,   0,252, 180,   0,252, 180,   0,
  74.   252,184,  0,252, 184,   0,252, 188,   0,252, 188,   0,
  75.   252,196,  0,252, 196,   0,252, 196,   0,252, 190,   0,
  76.   252,200,  0,252, 200,   0,252, 204,   0,252, 208,   0,
  77.   252,208,  0,252, 208,   0,252, 208,   0,252, 208,   0,
  78.   252,212,  0,252, 212,   0,252, 212,   0,252, 212,   0,
  79.   252,216,  0,252, 216,   0,252, 216,   0,252, 216,   0,
  80.   252,216,  0,252, 220,   0,252, 220,   0,252, 220,   0,
  81.   252,224,  0,252, 228,   0,252, 228,   0,252, 228,   0,
  82.   252,228,  0,252, 228,   0,252, 232,   0,252, 232,   0,
  83.   252,236,  0,252, 236,   0,252, 240,   0,252, 240,   0,
  84.   252,240,  0,252, 240,   0,252, 240,   0,252, 244,   0,
  85.   252,248,  0,252, 248,   0,252, 248,   0,252, 252,   0,
  86.   252,252,  4,252, 252,   8,252, 252,  12,252, 252,  16,
  87.   252,252, 20,252, 252,  24,252, 252,  28,252, 252,  32,
  88.   252,252, 36,252, 252,  40,252, 252,  40,252, 252,  44,
  89.   252,252, 48,252, 252,  52,252, 252,  56,252, 252,  60,
  90.   252,252, 64,252, 252,  68,252, 252,  72,252, 252,  76,
  91.   252,252, 82,252, 252,  84,252, 252,  86,252, 252,  88,
  92.   252,252, 92,252, 252,  96,252, 252, 100,252, 252, 104,
  93.   252,252,108,252, 252, 112,252, 252, 116,252, 252, 120,
  94.   252,252,124,252, 252, 124,252, 252, 128,252, 252, 132,
  95.   252,252,136,252, 252, 140,252, 252, 144,252, 252, 148,
  96.   252,252,152,252, 252, 154,252, 252, 162,252, 252, 164,
  97.   252,252,168,252, 252, 168,252, 252, 172,252, 252, 176,
  98.   252,252,180,252, 252, 184,252, 252, 188,252, 252, 192,
  99.   252,252,196,252, 252, 200,252, 252, 204,252, 252, 208,
  100.   252,252,208,252, 252, 212,252, 252, 216,252, 252, 220,
  101.   252,252,224,252, 252, 228,252, 252, 232,252, 252, 236,
  102.   252,252,240,252, 252, 244,252, 252, 248,252, 252, 252);
  103.  
  104. Var
  105.   FlameArr      : Array[0..99,0..159] Of Byte;
  106.   {^ the array to calculate everything }
  107.   B,P           : Byte;
  108.   { ^ some dummy variables }
  109.  
  110. Procedure PlotPixel ( X, Y : Word; C : Byte ); Assembler;
  111. { Sorry it's in assembler but I would be even slower if I didn't}
  112. Asm
  113.   Mov   AX, 320
  114.   Mul   Y           { Get the Y Pos ( Y * 320 cuz were in 320x200 mode ) }
  115.   Mov   DI, AX
  116.   Add   DI, X       { add the X value to find the offset }
  117.   Mov   AX, 0A000h
  118.   Mov   ES, AX      { set ES to the video seg }
  119.   Mov   AL, C
  120.   Mov   [ES:DI], AL { move the colour to the video memory }
  121. End;
  122.  
  123. Procedure CalcFlames;
  124. Var
  125.   X, Y    : Word;
  126.   { two variables for accessing the points in the array and screen }
  127.   Calc    : Word;
  128.   { a temp value for CALCulating things }
  129.  
  130. Begin
  131. { For flame effect scroll through every pixel and  }
  132. { choose some other pixels around it. Divide by    }
  133. { the ammount of pixels you added up and then      }
  134. { subtract a decay ammount.                        }
  135. {                                        2          }
  136. {  123   A23   X = 1+5+6/3 - Decay Value. = 4 - DV }
  137. {  3X5   3XB       ^ ^ ^                           }
  138. {  692   C92       A+B+C/3                         }
  139. {                                                  }
  140. { X = Pixel                                        }
  141. {                                                  }
  142.   For Y := 0 To 99 Do  { number of rows }
  143.     For X := 0 To 159 Do { number of cols }
  144.       Begin
  145.         Calc := FlameArr[Y+1,X] + FlameArr[Y+1,X-1] +
  146.           FlameArr[Y+1,X+1] + FlameArr[Y,X];
  147.           { add the values of the surrounding pixels }
  148.         FlameArr[Y,X] := Calc Div 4;
  149.         { divide by the number of pixels added up }
  150.         If FlameArr[Y,X] > 2 Then
  151.           Dec ( FlameArr[Y,X], 2 );
  152.         { decrement by the decay value }
  153.       End;
  154.   For X := 0 To 159 Do                    { Comment this and the next line }
  155.     FlameArr[99,X] := Random ( 204 ) + 11;{ for interesting effect }
  156.   { set a new bottom line }
  157.   For Y := 0 To 97 Do
  158.     For X := 0 To 159 Do
  159.       Begin
  160.         { plot the pixels to the screen }
  161.         PlotPixel ( X+80, Y+50, FlameArr[Y,X] );
  162.         { added 80 to X and 50 to Y to center on screen}
  163.        {PlotPixel ( X * 2, Y * 2, FlameArr[Y,X] );
  164.         PlotPixel ( X * 2+1, Y * 2+1, FlameArr[Y,X] );
  165.        {^^ Un-comment these two lines for a "Grid" Effect }
  166.       End;
  167. End;
  168.  
  169. Procedure SetColour ( Index, R, G, B : Byte );
  170. { Sets a colour to a specific RGB value }
  171. Begin
  172.   Port[$3C8] := Index;
  173.   Port[$3C9] := R;
  174.   Port[$3C9] := G;
  175.   Port[$3C9] := B;
  176. End;
  177.  
  178. Begin
  179.   { Change to MCGA 320x200x256 mode }
  180.   Asm
  181.     Mov AX, 13h
  182.     Int 10h
  183.   End;
  184.   { Initalize random seed }
  185.   Randomize;
  186.   { Clear the Flame Array }
  187.   FillChar ( FlameArr, SizeOf ( FlameArr ), 0 );
  188.   { calculate a new bottom line }
  189.   For B := 0 To 159 Do
  190.     FlameArr[99,B] := Random ( 204 ) + 11;
  191.   { make a the colours go from black to red }
  192.   For B := 0 To 255 Do
  193.     SetColour ( B, ( B * 43 ) Shr 7, 0, 0 );
  194.   Repeat
  195.     { calculate the flames }
  196.     CalcFlames;
  197.   { until ESC is pressed }
  198.   Until ( Port[$60] = $81 );
  199.   { go back to 80x25x16 text mode }
  200.   Asm
  201.     Mov AX, 3
  202.     Int 10h
  203.   End;
  204. End.
  205.